<?php
/**
 * Created by PhpStorm.
 * User: qzy008
 * Date: 2018/9/8
 * Time: 13:19
 */

namespace app\api\model;

use think\Model;

class Admin extends Model
{
    public static function createAdmin($params)
    {
        $params['status'] = 0; // 创建的管理员，默认状态是不可用的，只有经过super管理员授权才能使用。
        $admin = self::create($params);
        return $admin;
    }

    public static function deleteAdmin($id)
    {
        $result = self::destroy($id);
        return $result;
    }

    public static function updateAdmin($params)
    {
        $id = $params['id'];
        unset($params['id']);
        $result = self::where('id', '=', $id)
            ->update($params);
        return $result;
    }

    public static function readAdminByPassAccount($params)
    {
        $admin = self::where('account', '=', $params['account'])
            ->where('password', '=', $params['password'])
            ->find();
        return $admin;
    }

    public static function getAdminInfoByID($adminID)
    {
        $admin = self::find($adminID)->hidden(['id', 'password']);
        return $admin;
    }


}